<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <router-view></router-view>
        <router-link to="/home">首页</router-link>
        <router-link to="/company/123">公司详情1</router-link>
        <router-link to="/company/456">公司详情2</router-link>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="./node_modules/vue-router/dist/vue-router.js"></script>
<script>
    let routes = [{
        path: "/home",
        beforeEnter: (to, from, next) => {
            console.log("/home路由的导航守卫");
            next();
        },
        component: () => Promise.resolve({
            template: `<h1>这是首页</h1>`,
            beforeRouteEnter(to, from, next) {
                console.log("组件导航守卫,进入到组件的路由");
                next();
            },
            beforeRouteUpdate(to, from, next) {
                console.log("组件导航守卫,更新路由");
                next();
            },
            beforeRouteLeave(to, from, next) {
                console.log("组件导航路由,离开组件的路由");
                next();
            }
        })

    }, {
        path: "/product",
        component: () => Promise.resolve({
            template: `<h1>这是产品详情页面</h1>`,

        })
    }, {
        path: "/company/:id",

        beforeEnter: (to, from, next) => {
            console.log("路由 公司详情的导航守卫");
            next();
        },
        component: () =>
            import ("./jiekou.js")
    }]
    let router = new VueRouter({
        routes
    })
    router.beforeEach((to, from, next) => {
        console.log("全局的前置导航守卫");
        next();
    })

    let vm = new Vue({
        router,
        el: "#app",
    })
</script>

</html>